<template>
  <div class="pricing-management">
    <div class="header">
      <h2 class="header-title">司机费用管理</h2>
      <el-button type="primary" @click="openDialog" style="float: right">修改</el-button>
    </div>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="描述">
        <template v-slot:default="scope">
          <el-tag>{{ scope.row.label }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="金额">
        <template v-slot:default="scope">
          {{ scope.row.value }}  {{scope.row.unit}}
        </template>
      </el-table-column>
      <el-table-column label="说明">
        <template v-slot:default="scope">
          {{ scope.row.description }}
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="编辑司机费用" :visible.sync="dialogVisible">
      <el-form :model="formData">
        <el-form-item label="平台服务费" label-width="120px">
          <el-input v-model="formData.seriveFee" type="number" step="0.01"/>
        </el-form-item>
        <el-form-item label="平台管理费" label-width="120px">
          <el-input v-model="formData.feedbackFee" type="number" step="0.01"/>
        </el-form-item>
        <el-form-item label="保险费" label-width="120px">
          <el-input v-model="formData.insuranceFee" type="number" step="0.01"/>
        </el-form-item>
        <el-form-item label="处罚费" label-width="120px">
          <el-input v-model="formData.punishmentFee" type="number" step="0.01"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="saveChanges">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { selectDriverPayRule, updateDriverPayRule } from '@/api/operate/dirver'

export default {
  data() {
    return {
      dialogVisible: false,
      formData: {
        seriveFee: 0,
        feedbackFee: 0,
        insuranceFee: 0,
        punishmentFee: 0
      },
      resData: {}
    }
  },
  computed: {
    tableData() {
      return [
        {
          label: '平台服务费',
          value: this.formData.seriveFee,
          description: '平台服务费（收益抽成）',
          unit: '%/单'
        },
        {
          label: '平台管理费',
          value: this.formData.feedbackFee,
          description: '平台管理费（收益抽成）',
          unit: '%/单'
        },
        {
          label: '保险费',
          value: this.formData.insuranceFee,
          description: '保险费（每月固定扣除）',
          unit: '元/月'
        },
        {
          label: '处罚费',
          value: this.formData.punishmentFee,
          description: '处罚扣费（根据拒单金额额外扣除）',
          unit: '元/单'
        }
      ]
    },
  },
  methods: {
    openDialog() {
      this.dialogVisible = true
    },
    saveChanges() {
       // 处理保存逻辑，例如调用API保存更改的数据
      updateDriverPayRule(this.formData).then(res => {
        this.$modal.success('保存成功,次日自动生效')
      })
      console.log('保存数据:', this.formData)
      this.dialogVisible = false
    },
    getDriverPayRule(){
      //初始化表单数据
      selectDriverPayRule().then(res => {
        this.formData = res.data
      })
    }
  },
  created() {
    this.getDriverPayRule()
  }
}
</script>

<style scoped>
.pricing-management {
  padding: 20px;
}

.header {
  margin-bottom: 20px;
}

.header-title {
  font-size: 18px;
  display: inline;
}
</style>
